package com.zx.sdk.listener;

import static com.zx.sdk.ZxSDK.BANNER;

import com.zx.sdk.ZxSDK;
import com.zx.sdk.league.member.BaseLeagueMember;
import com.zx.sdk.model.AdInfo;
import com.zx.sdk.model.ZxError;
import com.zx.sdk.util.ConfigHelper;
import com.zx.sdk.util.LogHelper;
import com.zx.sdk.util.ZxEventHelper;

public abstract class BaseZxBannerListener implements ZxBannerListener {

    @Override
    public void onAdReady(Object object, BaseLeagueMember<?, ?, ?, ?, ?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Banner广告onAdReady", "appId="+ adInfo.getMapAppid(), "pid="+ adInfo.getMapPid());
        ZxEventHelper.record(BANNER, ZxEventHelper.LOADED, adInfo, member);
        onAdReady(object);
    }

    @Override
    public void onAdShow(Object object, BaseLeagueMember<?, ?, ?, ?, ?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Banner广告onAdShow", "appId="+ adInfo.getMapAppid(), "pid="+ adInfo.getMapPid());
        ZxEventHelper.record(BANNER, ZxEventHelper.EXPOSE, adInfo, member);
        ZxSDK.notifyClearBidding(BANNER, adInfo.getMapPid());
        onAdShow(object);
        ConfigHelper.showBanner();
    }

    @Override
    public void onAdClick(Object object, BaseLeagueMember<?, ?, ?, ?, ?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Banner广告onAdClick", "appId="+ adInfo.getMapAppid(), "pid="+ adInfo.getMapPid());
        ZxEventHelper.record(BANNER, ZxEventHelper.CLICK, adInfo, member);
        onAdClick(object);
        if (adInfo.getAdType() == AdInfo.AD_TYPE_SUSPENSION) {
            ZxSDK.uploadHitInformation(adInfo.getMapAppid(), adInfo.getMapPid(), 0, 2);
        }
    }

    @Override
    public void onAdFailed(ZxError error, BaseLeagueMember<?, ?, ?, ?, ?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Banner广告onAdFailed", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid(), "error=" + error.getErrorCode() + error.getErrorMsg());
        onAdFailed(error);
    }

    @Override
    public void onAdSwitch(BaseLeagueMember<?, ?, ?, ?, ?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Banner广告onAdSwitch", "appId="+ adInfo.getMapAppid(), "pid="+ adInfo.getMapPid());
        onAdSwitch();
    }

    @Override
    public void onAdClose(Object object, BaseLeagueMember<?, ?, ?, ?, ?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Banner广告onAdClose", "appId="+ adInfo.getMapAppid(), "pid="+ adInfo.getMapPid());
        onAdClose(object);
        ConfigHelper.closeSuspension();
    }

    @Override
    public void setOnPreloadErrorListener(OnPreloadErrorListener listener) {

    }

    @Override
    public void setOnShowErrorListener(OnShowErrorListener listener) {

    }

    @Override
    public void setOnADExposeListener(OnADExposeListener listener) {

    }

    public abstract void onAdReady(Object object);

    public abstract void onAdShow(Object object);

    public abstract void onAdClick(Object object);

    public abstract void onAdFailed(ZxError error);

    public abstract void onAdSwitch();

    public abstract void onAdClose(Object object);

}
